package com.temple.core 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.FocusEvent;
	import flash.events.MouseEvent;
	import flash.net.SharedObject;
	import flash.utils.Dictionary;
	/**
	 * ...
	 * @author hungconcon
	 */
	public class Module extends EventDispatcher {
		/**
		 * 
		 */
		private static var module:Module;
		/**
		 * 
		 */
		private var	stageover:*;
		/**
		 * 
		 */
		private var	stagedown:*;
		/**
		 * 
		 */
		private var	stagevalue:*;
		/**
		 * 
		 */
		private var isdown:Boolean = false;
		/**
		 * A set of elements shown on the state presentation.
		 * The elements
		 */
		private var dic:Dictionary;
		/**
		 * Singleton UI Manager roll by mouse.
		 */
		public function Module() {
			dic = new Dictionary();
		}
		/**
		 * Singleton instance
		 */
		public static function get stage():Module{
            if(!module) module = new Module();
            return module;
        }
		/*******************************************
		 * Add all ui registry, that mean this never delete
		 * @param	value
		 * @param	key
		 ******************************************/
		public function add(ui:*, key:String):void {
			dic[key] =  ui;			
			try{
				ui.addEventListener(MouseEvent.CLICK		, onMouseEvent);
				ui.addEventListener(MouseEvent.DOUBLE_CLICK	, onMouseEvent);
				ui.addEventListener(MouseEvent.MOUSE_DOWN	, onMouseEvent);
				ui.addEventListener(MouseEvent.MOUSE_MOVE	, onMouseEvent);
				ui.addEventListener(MouseEvent.MOUSE_UP		, onMouseEvent);
				ui.addEventListener(MouseEvent.MOUSE_WHEEL	, onMouseEvent);
				ui.addEventListener(MouseEvent.ROLL_OUT		, onMouseEvent);
				ui.addEventListener(MouseEvent.ROLL_OVER	, onMouseEvent);
			}catch(ex:Error){}
		}
		public function ui(key:String):*{
			return dic[key];
		}
		/**************************************
		 * switch event mouse
		 * @param	event
		 *************************************/
		private function onMouseEvent(event:MouseEvent):void {
			switch (event.type) {
				case MouseEvent.DOUBLE_CLICK:  break;
				case MouseEvent.MOUSE_WHEEL	:  break;
				case MouseEvent.CLICK		:  break;
				case MouseEvent.MOUSE_MOVE	:  break;
				case MouseEvent.MOUSE_UP	:  
					stagevalue = event.currentTarget; 
					isdown = false;
				break;
				case MouseEvent.ROLL_OUT	:  break;
				case MouseEvent.MOUSE_DOWN	:  isdown = true; break;
				case MouseEvent.ROLL_OVER	:  stagevalue = event.currentTarget; break;
			}
			dispatchEvent(event);			
		}
		/************************************
		 * Singleton send notification
		 ***********************************/
		public function sendNotification(types:String, object:* = null):void {
			if (object == null){
				object = { };
			}
			dispatchEvent(new ModuleEvent(types, object));
		}
		/************************************
		 * Set and Get current element action!
		 ***********************************/
		public function set	objectByRoll(value:*):void{ stageover = value; 	}
		public function get	objectByRoll():*{ return stageover; 				}
		public function set	objectByDown(value:*):void { stagedown = value; 	}
		public function get	objectByDown():*{ 	return stagedown;  			}
		public function set	stateValue(value:*):void { stagevalue = value; 	}
		public function get	stateValue():*{ 	return stagevalue;  			}
		public function set	isDown(value:*):void { isdown = value; 	}
		public function get	isDown():Boolean { return isdown;  		}
		
		
	}
}